<template>
  <div>
    <el-container>
      <el-asid :width="asidWidth" class="el-asid">
        <div
            style="height: 70px;color:#fff; display:flex; align-items:center;justify-content:center"
        >
          <span>医院预约挂号系统</span>
        </div>

        <!-- 侧边栏 -->
        <el-menu
            :collapse="isCollapse"
            :collapse-transition="false"
            active-text-color="#fff"
            text-color="#b3b9bf"
            background-color="#001529"
            router
            style="border: none;"
            :default-active="$route.path"
        >
          <el-menu-item index="/" style="width: 200px;">
            <i class="el-icon-s-home"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>
          <el-submenu index="1"  v-if="user.role === 'ADMIN'">
            <template slot="title">
              <i class="el-icon-message"></i>
              <span>信息管理</span>
            </template>
            <el-menu-item index="/Announcement">公告信息</el-menu-item>
            <el-menu-item index="/Administrative">科室信息</el-menu-item>
            <el-menu-item index="/Scheduling">医生排班</el-menu-item>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-message"></i>
              <span>预约就诊</span>
            </template>
            <el-menu-item index="/Appointment">预约挂号</el-menu-item>
            <el-menu-item index="/Patient">患者挂号</el-menu-item>
            <el-menu-item index="/PatientAttendance">患者就诊</el-menu-item>
            <el-menu-item index="/Hospital">住院登记</el-menu-item>
          </el-submenu>
          <el-submenu index="3" v-if="user.role === 'ADMIN'">
            <template slot="title">
              <i class="el-icon-message"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item index="/Admin">管理员信息</el-menu-item>
            <el-menu-item index="/Doctor">医生信息</el-menu-item>
            <el-menu-item index="/User">用户信息</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-asid>

      <!-- 右边区域 -->
      <el-container>
        <!-- 头部 -->
        <el-header>
          <div style=" display:flex; align-items:center;width:100px ;height:60px; float: left">
            <span style=" float :left ;">
              <i class="el-icon-s-fold" style=" font-size: 25px; padding-right: 20px"></i>
            </span>
            <span style="float:right">头部</span>
          </div>
          <div style="float: right ; height:60px; line-height: 60px; ">
            <el-dropdown>
              <span class="el-dropdown-link">
                <!-- 这里进行判断，如果username有值则使用，没有值则使用account  -->
                {{ user.username ? user.username : user.account }}
                <i
                    class="el-icon-arrow-down el-icon--right"
                ></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>
                  <div @click="logout()">退出登录</div>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>

        <!-- 内容区域 -->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Common",
  data() {
    return {
      isCollapse: false, //不收缩
      asidWidth: "200px", //侧边栏宽度
      // user用于存放用户的name
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {}
    };
  },
  methods: {
    //侧边栏收缩
    UpdateIsCollapse() {
      this.isCollapse = !this.isCollapse;
      this.asidWidth = this.isCollapse ? "64px" : "200px";
    },

    //退出登录
    logout() {
      // 删除user
      localStorage.removeItem("user");
      // 跳转到登录页面
      this.$router.push("/login");
    }
  }
};
</script>

<style scoped>
.el-submenu .el-menu-item {
  width: 160px;
}

.el-menu--inline .el-menu-item {
  background-color: #000c17 !important;
}

.el-menu-item:hover {
  color: #fff !important;
}

.el-submenu /deep/ .el-submenu__title:hover i {
  color: #fff !important;
}

.el-submenu /deep/ .el-submenu__title:hover {
  color: #fff !important;
}

li.el-menu-item.is-active {
  background-color: #0960bd !important;
}

.el-asid {
  transition: all 2s;
  box-shadow: 2px 0 6px rgba(0, 21, 41, 0.35) !important;
  min-height: 100vh;
  background-color: #001529;
}

.el-header {
  box-shadow: 2px 0 6px rgba(0, 21, 41, 0.35);
}

.el-main {
  padding: 10px;
}
</style>
  